use std::time::Instant;

// Calculate the nth Fibonacci number
fn fib(n: isize) -> isize {
    if n <= 2 {
        1
    } else {
        let mut a = 1;
        let mut b = 1;
        for _i in 3..=n {
            let temp = b;
            b = b + a;
            a = temp;
        }
        b
    }
}

fn main() {
    let start = Instant::now();

    let mut result: isize = 0;
    let mut num = 0;

    // Call the fib function
    for i in 1..=500 {
        result = fib(i);
        num = i; // Just to keep the same variable name as in the original code
    }
    println!("{}",num);

    // Record end time and print results
    let duration = start.elapsed();
    println!("Rust time: {:.6?}\nFibonacci number is: {}", duration, result);
}